package app.sceledroid.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import app.sceledroid.R;
import app.sceledroid.entity.Deadline;

public class DeadlineAdapter extends ArrayAdapter<Deadline> {

	private ArrayList<Deadline> deadlines;
	
	public DeadlineAdapter(Context context, int textViewResourceId,
			ArrayList<Deadline> deadlines) {
		super(context, textViewResourceId, deadlines);
		// TODO Auto-generated constructor stub
		this.deadlines = deadlines;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		if (v == null) {
			Context context = super.getContext();
			LayoutInflater vi = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.course_deadline_item, null);
		}
		Deadline d = deadlines.get(position);
		
		TextView deadlineName = (TextView)v.findViewById(R.id.deadlineItemName);
		deadlineName.setText(d.getName());
		TextView deadlineStartDate = (TextView)v.findViewById(R.id.deadlineItemStartDate);
		//SimpleDateFormat df = new SimpleDateFormat("");
		deadlineStartDate.setText( DateFormat.getDateTimeInstance().format(d.getDateStart()));
		TextView deadlineEndDate = (TextView)v.findViewById(R.id.deadlineItemEndDate);
		deadlineEndDate.setText(DateFormat.getDateTimeInstance().format(d.getDateEnd()));
		
		
		
		return v;
	}
	

}
